Get `make test` working on MSVC
authorAlex Crichton <alex@alexcrichton.com>
Fri, 26 Jun 2015 22:51:53 +0000 (15:51 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 26 Jun 2015 23:06:16 +0000 (16:06 -0700)
This commit updates Cargo's unit tests to pass `make check` entirely on MSVC
targets. Two tests are ignored on MSVC as it requires panicking to be
implemented, which currently isn't, but otherwise Cargo is fully functional.

tests/test_cargo_bench.rs
tests/test_cargo_compile.rs
tests/test_cargo_compile_plugins.rs
tests/test_cargo_test.rs
tests/tests.rs

index 4c3a9f19db48e1e6af27eb80069a471f68dd7044..9d0123ec6c681888c2c7231675868f26995796e3 100644 (file)
@@ -154,6 +154,7 @@ test!(many_similar_names {
 
 test!(cargo_bench_failing_test {
     if !::is_nightly() { return }
+    if !::can_panic() { return }
 
     let p = project("foo")
         .file("Cargo.toml", &basic_bin_manifest("foo"))
index 02cfa26649f0dc9f67333f604dba695a1731e97e..eb4c49359e724b2607a122bbece6de99931a2f3d 100644 (file)
@@ -722,24 +722,12 @@ test!(many_crate_types_old_style_lib_location {
         .file("src/foo.rs", r#"
             pub fn foo() {}
         "#);
-    assert_that(p.cargo_process("build"),
-                execs().with_status(0));
+    assert_that(p.cargo_process("build"), execs().with_status(0));
 
-    let files = fs::read_dir(&p.root().join("target/debug")).unwrap();
-    let mut files: Vec<String> = files.map(|e| e.unwrap().path()).filter_map(|f| {
-        match f.file_name().unwrap().to_str().unwrap() {
-            "build" | "examples" | "deps" => None,
-            s if s.contains("fingerprint") || s.contains("dSYM") => None,
-            s => Some(s.to_string())
-        }
-    }).collect();
-    files.sort();
-    let file0 = &files[0];
-    let file1 = &files[1];
-    println!("{} {}", file0, file1);
-    assert!(file0.ends_with(".rlib") || file1.ends_with(".rlib"));
-    assert!(file0.ends_with(env::consts::DLL_SUFFIX) ||
-            file1.ends_with(env::consts::DLL_SUFFIX));
+    assert_that(&p.root().join("target/debug/libfoo.rlib"), existing_file());
+    let fname = format!("{}foo{}", env::consts::DLL_PREFIX,
+                        env::consts::DLL_SUFFIX);
+    assert_that(&p.root().join("target/debug").join(&fname), existing_file());
 });
 
 test!(many_crate_types_correct {
@@ -763,21 +751,10 @@ test!(many_crate_types_correct {
     assert_that(p.cargo_process("build"),
                 execs().with_status(0));
 
-    let files = fs::read_dir(&p.root().join("target/debug")).unwrap();
-    let mut files: Vec<String> = files.map(|f| f.unwrap().path()).filter_map(|f| {
-        match f.file_name().unwrap().to_str().unwrap() {
-            "build" | "examples" | "deps" => None,
-            s if s.contains("fingerprint") || s.contains("dSYM") => None,
-            s => Some(s.to_string())
-        }
-    }).collect();
-    files.sort();
-    let file0 = &files[0];
-    let file1 = &files[1];
-    println!("{} {}", file0, file1);
-    assert!(file0.ends_with(".rlib") || file1.ends_with(".rlib"));
-    assert!(file0.ends_with(env::consts::DLL_SUFFIX) ||
-            file1.ends_with(env::consts::DLL_SUFFIX));
+    assert_that(&p.root().join("target/debug/libfoo.rlib"), existing_file());
+    let fname = format!("{}foo{}", env::consts::DLL_PREFIX,
+                        env::consts::DLL_SUFFIX);
+    assert_that(&p.root().join("target/debug").join(&fname), existing_file());
 });
 
 test!(unused_keys {
index 01011e5b48c9db8813f6c5ab9a9612d424c87da9..3d90bd10645f1fc114f6297a88fe1bd5b5770c25 100644 (file)
@@ -218,7 +218,9 @@ test!(doctest_a_plugin {
             name = "bar"
             plugin = true
         "#)
-        .file("bar/src/lib.rs", "");
+        .file("bar/src/lib.rs", r#"
+            pub fn bar() {}
+        "#);
 
     assert_that(p.cargo_process("test").arg("-v"),
                 execs().with_status(0));
index 876cd8d588b527baea7c4d7a60e48240e1abab70..91304272a3c8dfd01e187cc806e379b2687b28d6 100644 (file)
@@ -164,6 +164,8 @@ test!(many_similar_names {
 });
 
 test!(cargo_test_failing_test {
+    if !::can_panic() { return }
+
     let p = project("foo")
         .file("Cargo.toml", &basic_bin_manifest("foo"))
         .file("src/foo.rs", r#"
@@ -690,7 +692,7 @@ test!(bin_there_for_integration {
             authors = []
         "#)
         .file("src/main.rs", "
-            fn main() { panic!(); }
+            fn main() { std::process::exit(101); }
             #[test] fn main_test() {}
         ")
         .file("tests/foo.rs", r#"
index 6aba35471fd724c4e7583a5e8546631e048c4763..b82c2ecf5ff85db1111ba36587cae9588622d3e0 100644 (file)
@@ -65,3 +65,8 @@ fn is_nightly() -> bool {
     let version_info = cargo::ops::rustc_version("rustc").unwrap().0;
     version_info.contains("-nightly") || version_info.contains("-dev")
 }
+
+fn can_panic() -> bool {
+    let host = cargo::ops::rustc_version("rustc").unwrap().1;
+    !host.contains("msvc")
+}